/**
 * 文件命名格式：zmn.模块名称.表名称.功能.js
 * @author wangjie
 * @since 2019/06/13 13:58
 */
layui.define(['index', 'form'], function (exports) {
    let $ = layui.$;
    let layer = layui.layer;
    let form = layui.form;

    zmnLayUtil.layFormVerify(form,{
        maxLengthVarcharPer:30
    });

    //监听提交
    form.on('submit(zmn-form-submit)', function (obj) {

        let data = obj.field;
        let serv = {};
        let arr = new Array();
        $("input:checkbox[name='faultGroup']:checked").each(function (i) {
            arr[i] = $(this).val();
        });
        serv.groupIds = arr;
        serv.bizType = json.bizType;
        serv.productId = json.productId;
        serv.tariffId = json.tariffId;
        serv.desc = data.desc;
        serv.specialDesc = data.specialDesc;
        serv.status = data.status;
        serv.general = data.general;

        if (arr.length === 0){
            layer.msg("请选择服务项分组", {"icon": 2});
            return false;
        }

        var url = "/product/tariff/saveProductPriceTable.action";

        zmnLayUtil.ajaxSimpleJson(url, serv, 0, function (rs) {
            if (rs.status === 200) {
                parent.layui.layer.msg(rs.message,{time: 1000},()=>{
                    cancel();
                    return true;
                });

            }else {
                parent.layui.layer.msg(rs.message,{"icon":2});
                return false;
            }
        });
        return false;
    });

    //点击取消
    $(document).on('click', '#cancel', function () {
        zmnLayUtil.closeThisIframe(parent);
    });

    //对外暴露的接口
    exports('serv_product_tariff_modify', {});
});

function cancel() {
    window.location.href="/product/tariff/group/listTable.action?productId="+json.productId+"&keepType="+"&tariffId="+json.tariffId;
}

